#include "EnclaveWrap_t.h"

#include "sgx_trts.h"
#include "stdio.h"

void printf(const char *fmt, ...)
{
    char buf[4096] = { 0 };

    va_list ap;
    va_start(ap, fmt);

    vsnprintf(buf, 4096, fmt, ap);

    ocall_print_string(buf);

    va_end(ap);
}

void log_info(const char *fmt, ...)
{
	const int buf_size = 4096;
	char buf[buf_size] = { 0 };
	va_list ap;
	va_start(ap, fmt);
	vsnprintf(buf, buf_size - 1, fmt, ap);
	va_end(ap);

	ocall_log_info(buf);
}

void log_warning(const char *fmt, ...)
{
	const int buf_size = 4096;
	char buf[buf_size] = { 0 };
	va_list ap;
	va_start(ap, fmt);
	vsnprintf(buf, buf_size - 1, fmt, ap);
	va_end(ap);

	ocall_log_warning(buf);
}

void log_error(const char *fmt, ...)
{
	const int buf_size = 4096;
	char buf[buf_size] = { 0 };
	va_list ap;
	va_start(ap, fmt);
	vsnprintf(buf, buf_size - 1, fmt, ap);
	va_end(ap);

	ocall_log_error(buf);
}

void log_fatal(const char *fmt, ...)
{
	const int buf_size = 4096;
	char buf[buf_size] = { 0 };
	va_list ap;
	va_start(ap, fmt);
	vsnprintf(buf, buf_size - 1, fmt, ap);
	va_end(ap);

	ocall_log_fatal(buf);
}